package easy

import "strconv"

func CalPoints(operations []string) int {
	arr := []int{}
	var ans int
	for _, op := range operations {
		n := len(arr)
		switch op[0] {
		case '+':
			ans += arr[n-1] + arr[n-2]
			arr = append(arr, arr[n-1]+arr[n-2])
		case 'D':
			ans += arr[n-1] * 2
			arr = append(arr, 2*arr[n-1])
		case 'C':
			ans -= arr[n-1]
			arr = arr[:len(arr)-1]
		default:
			pt, _ := strconv.Atoi(op)
			ans += pt
			arr = append(arr, pt)
		}
	}
	return ans
}
